package day08.ZiXi;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
//迭代器
public class Collection02 {
    public static void main(String[] args) {
        //创建集合
        //Collection<String> c = new ArrayList<>();
        Collection<String> c = new ArrayList<>();
        //添加元素
        c.add("a");
        c.add("b");
        c.add("c");
        c.add("d");
        c.add("e");
        //Iterator<E> iterator()：返回此集合中元素的迭代器，通过集合的iterator()方法得到
        //Iterator<String> it = c.iterator();
        Iterator<String> it = c.iterator();
        ////用while循环改进元素的判断和获取
        //while (it.hasNext()){
        while (it.hasNext()){
            //String s = it.next();
            String s = it.next();
            System.out.println(s);
        }
    }
}
